#include "comm.hpp"
#define SIZE 4096
#define fifoname "./fifo"
int main(){
    int shmid = creatShm(SIZE);//创建共享内存
    char* addr = (char*)shmat(shmid,nullptr,0);//链接共享内存到地址空间
    log("debug","\"shmat shared memory\" success",__FILE__,__LINE__);
     //创建命名管道
    if(mkfifo(fifoname,0666) == -1){
        log("error","\"mkfifo\" failed",__FILE__,__LINE__);
    }
    int fd = open(fifoname,O_RDONLY);
    if(fd<0){
        log("error","\"open\" failed",__FILE__,__LINE__);
    }//命名管道创建并打开成功
    log("debug","\"open fifo\" success",__FILE__,__LINE__);

    while(true){
        char* buf[2] = {0};
        int n = read(fd,buf,sizeof(buf));
        if(n==0) break;//写端管道以关闭
        cout<<addr<<endl;
    }

    close(fd);
    unlink(fifoname);//服务端现启动,由sever来负责删除管道和删除共享内存较好
    shmdt(addr);
    destoryShm(shmid);
    return 0;
}